<template>
  <div>
    <!-- 搜索 -->
    <div class="findstudents" size="small">
      <template>
        <el-select v-model="finder" size="small" style="width:150px">
          <el-option
            v-for="item in find"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            class="find"
          ></el-option>
        </el-select>
        <el-input placeholder="请输入内容" v-model="input" clearable size="small" style="width:300px"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="findlist" size="small">搜索</el-button>
      </template>
    </div>
    <el-table
      :data="goodsData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
      style="width: 100%"
    >
      <el-table-column label="名称" prop="name"></el-table-column>
      <el-table-column label="商品种类" prop="classify"></el-table-column>
      <el-table-column label="适用宠物" prop="pet"></el-table-column>
      <el-table-column label="价格" prop="price"></el-table-column>
      <el-table-column label="重量" prop="weight"></el-table-column>
      <el-table-column label="生产日期" prop="production"></el-table-column>
      <el-table-column label="保质期" prop="shelfLife"></el-table-column>
      <el-table-column label="产地" prop="producer"></el-table-column>
      <el-table-column label="商品图片" prop="images">
      <template slot-scope="scope">
       <img :src= "scope.row.images"  class="temp" />
      </template>
      </el-table-column>
      <el-table-column label="商品描述" prop="desc"></el-table-column>
      <el-table-column align="right">
        <template slot-scope="scope" class="operate">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[5, 8, 12 ]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="listdata.totalCount"
    ></el-pagination>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapActions, mapMutations } = createNamespacedHelpers("goods");

export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄"
        }
      ],
      find: [
        { value: "name", label: "名称" },
        { value: "classify", label: "商品种类" },
        { value: "pet", label: "适用宠物" },
        { value: "price", label: "价格" },
        { value: "weight", label: "重量" },
        { value: "production", label: "生产日期" },
        { value: "shelfLife", label: "保质期" },
        { value: "producer", label: "产地" },
        { value: "desc", label: "商品描述" }
      ],
      currentPage4: 1,
      search: "",
      finder: "name",
      input: ""
    };
  },
  mounted() {
    this.getlist({ ...this.listdata });
    // console.log(this.goodsData);
  },
  computed: {
    //获取仓库数据
    ...mapState(["goodsData", "listdata"])
  },
  methods: {
    //获取仓库得方法
    ...mapActions(["getlist", "dle"]),
    ...mapMutations(["pageSize", "currentPage"]),

    handleSizeChange(val) {
      this.pageSize({ pageSize: val });
      console.log(`每页 ${val} 条`);
      this.getlist({ ...this.listdata });
    },
    handleCurrentChange(val) {
      this.currentPage({ currentPage: val });
      console.log(`当前页: ${val}`);
      this.getlist({ ...this.listdata });
    },
    handleEdit(index, row) {
      localStorage.obj = JSON.stringify(row);
      this.$router.replace("/system/updategoods");

      console.log(index);
    },
    handleDelete(index, row) {
      alert("确认删除");
      this.dle({ _id: row._id });
      this.getlist({ ...this.listdata });
      Location.reload()
      // console.log(index, row);
    },
    findlist: function() {
      console.log(123);

      let type = this.finder;
      let value = this.input;
      //   调用mutations方法，讲查询条件存入厂库，用于查询使用
      this.getlist({ type, value });
      // 调用getter方法
      // this.finding();
    }
  }
};
</script>
<style >

.temp{
  width: 100%;
  height: 100%;
}
.find {
  width: 150px;
}
</style>